unit UnitSettingsStyleSeries;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, TeCanvas, Spin, UserSession;

type
  TFormSeriesSettings = class(TForm)
    Label1: TLabel;
    ComboBox1: TComboBox;
    SpinEdit1: TSpinEdit;
    Label2: TLabel;
    ButtonColor1: TButtonColor;
    ColorDialog1: TColorDialog;
    Button1: TButton;
    Button2: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
    FSave: TSeriesData;
    hEsc: LongInt;
//    hEnter: LongInt;
    procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;
  public
    { Public declarations }
    property Save: TSeriesData read FSave;
    property LineColor: TColor read FSave.Color;
    property LineWidth: LongInt read FSave.Width;
    property LineStyle: LongInt read FSave.Style;
  end;

var
  FormSeriesSettings: TFormSeriesSettings;

implementation

{$R *.dfm}

procedure TFormSeriesSettings.FormCreate(Sender: TObject);
begin
  ModalResult := mrCancel;
  SpinEdit1.MinValue := 1;
  SpinEdit1.MaxValue := 100;
  SpinEdit1.Value := SpinEdit1.MinValue;
  ComboBox1.ItemIndex := 0;
  with FSave do
  begin
    Color := clRed;
    Width := SpinEdit1.MinValue;
    Style := ComboBox1.ItemIndex;
  end;
  hEsc := GlobalAddAtom('hEsc_SeriesSettings');
  RegisterHotKey(Handle, hEsc, 0, VK_ESCAPE);
//  hEnter := GlobalAddAtom('hEnter_SeriesSettings');
//  RegisterHotKey(Handle, hEnter, 0, VK_RETURN);
end;

procedure TFormSeriesSettings.FormDestroy(Sender: TObject);
begin
//  UnregisterHotKey(Handle, hEnter);
  UnregisterHotKey(Handle, hEsc);
end;

procedure TFormSeriesSettings.Button1Click(Sender: TObject);
begin
  with FSave do
  begin
    Color := ButtonColor1.SymbolColor;
    Width := SpinEdit1.Value;
    if (ComboBox1.ItemIndex < 0) then
     Style := 1
    else
     Style := ComboBox1.ItemIndex;
  end;
  ModalResult := mrOk;
end;

procedure TFormSeriesSettings.Button2Click(Sender: TObject);
begin
  with FSave do
  begin
    ButtonColor1.SymbolColor := Color;
    SpinEdit1.Value := LineWidth;
    ComboBox1.ItemIndex := LineStyle;
  end;
  ModalResult := mrCancel;
end;

procedure TFormSeriesSettings.FormShow(Sender: TObject);
begin
  ModalResult := mrCancel;
end;

procedure TFormSeriesSettings.ComboBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
  drawline: Boolean;
begin
  drawline := True;
  with TComboBox(Control).Canvas do
  begin
//    if Selected then
//     Brush.Color := clHighlight
//    else
//     Brush.Color := clBtnFace;
    FillRect(Rect);
    case Index of
      0: Pen.Style := psSolid;
      1: Pen.Style := psDash;
      2: Pen.Style := psDot;
      3: Pen.Style := psDashDot;
      4: Pen.Style := psDashDotDot;
      else
      begin
        drawline := False;
        TextOut(Rect.Left, Rect.Top, TComboBox(Control).Items[Index]);
      end;
    end;
    if drawline then
    begin
      MoveTo(Rect.Left, (Rect.Top + Rect.Bottom) div 2);
      LineTo(Rect.Right - 5, (Rect.Top + Rect.Bottom) div 2);
    end;
  end;
end;

procedure TFormSeriesSettings.WMHotKey(var Msg: TWMHotKey);
begin
  with Msg do
  begin
    if (HotKey = hEsc) then
     ModalResult := mrCancel;
  end;
end;

end.
